
import 'antd/dist/antd.less';
import '../globals.css'
import Head from 'next/head';
import RenderJudge from '@/components/RenderJudge';
import App from 'next/app'
const MODE = process.env.NODE_ENV
const isProd = process.env.NODE_ENV === "production"
import { Provider } from "react-redux";
import withRedux from "@/store/withRedux"
import zhCN from 'antd/lib/locale/zh_CN';
import { ConfigProvider } from 'antd';
import Icon from "@/assets/icon.png";
import { isMobile } from "@/common/tool"
import { useRouter } from 'next/router'
import { DotLoading } from 'antd-mobile/2x'
import { useSafeState } from 'ahooks';
import { BackTop } from 'antd';
function nextApp ({ Component, pageProps, ReduxStore, mobile }) {
  const getLayout = Component.getLayout || (page => page);
  // eslint-disable-next-line react-hooks/rules-of-hooks
  const [loading, setLoading] = useSafeState(false)
  // eslint-disable-next-line react-hooks/rules-of-hooks
  const router = useRouter();

  if (router?.events?.on) {
    router.events.on('routeChangeStart', (p) => {
      setLoading(true)
    });
    router.events.on('routeChangeComplete', () => {
      setLoading(false)
    });
    router.events.on('routeChangeError', () => {
      setLoading(false)
    });
  }
  // eslint-disable-next-line react-hooks/rules-of-hooks
  // useEffect(() => {
  //   document.body.style.setProperty('--bgfff', '#333333')
  //   document.body.style.setProperty('--bgcolor', '#333333')
  //   document.body.style.setProperty('--font333', '#FFF')
  //   document.body.style.setProperty('--font999', '#FFF')
  //   document.body.style.setProperty('--fontfff', '#333333')
  // }, [])
  return (
    <>
      <RenderJudge value={loading} active={
        <DotLoading color="primary" style={{ position: "absolute", left: '50%', top: '50%', zIndex: 3, transform: 'translate(-50%,-50%)' }} />
      } />

      <Head >
        <meta build-env={MODE} build-version="1" />
        <meta httpEquiv="Content-Type" content="text/html; charset=UTF-8" />
        {/* <!-- 启用360浏览器的极速模式(webkit) --> */}
        <meta name="renderer" content="webkit" />
        {/* <!-- 避免IE使用兼容模式 --> */}
        <meta httpEquiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
        {/* <!-- 网页不会被缓存 --> */}
        <meta httpEquiv="Pragma" content="no-cache" />
        <meta httpEquiv="Cache-Control" content="no-cache" />
        <link rel="icon" href={Icon.src} type='image/x-icon' />
        <meta httpEquiv="Expires" content="0" />
        {/* <!-- 忽略页面中的数字识别为电话号码、email识别 --> */}
        <meta name="format-detection" content="telephone=no, email=no" />
        <meta name="baidu-site-verification" content="code-5WZBHizq5d" />
        <meta name="360-site-verification" content="f9056a0fdd50a0c6fa1ecf842336b094" />
      </Head>
      <Provider store={ReduxStore} >
        <ConfigProvider locale={zhCN}>
          {getLayout(<Component {...pageProps} mobile={mobile} />, { mobile })}
        </ConfigProvider>
      </Provider>
      <RenderJudge value={mobile} inactive={<BackTop />} />
    </>
  )
}
nextApp.getInitialProps = async (ctx) => {
  const mobile = isMobile(ctx?.ctx?.req?.headers['user-agent'])
  const appProps = await App.getInitialProps(ctx);
  return { ...appProps, mobile };
};
export default withRedux(nextApp)
